package cn.cloudmenu.android.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import cn.cloudmenu.android.R;

public class FavoriteMenu extends Activity {

	/** Called when the activity is first created. */
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.favorite_menu);
		System.out.println("FavoriteMenu webview this.findViewById(R.id.favorite_menu_webview) = "+this.findViewById(R.id.favorite_menu_webview));
		WebView webView = (WebView)this.findViewById(R.id.favorite_menu_webview);
		String href = getResources().getString(R.string.favorite_menu_set);
		TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 
		href = href + tm.getDeviceId();
		System.out.println("FavoriteMenu.onCreate() href = "+href);
		webView.loadUrl(href);
		//webView.loadUrl("http://jquerymobile.com/demos/1.0a4.1/");
		
		WebSettings webSettings = webView.getSettings();          
	      webSettings.setJavaScriptEnabled(true);  
	      webSettings.setSaveFormData(false);  
	      webSettings.setSavePassword(false);  
	      webSettings.setSupportZoom(false);
	      webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
	      //myjs是自己定义的，供javascript访问的接口  
	      // this is necessary for "alert()" to work  
	      webView.setWebChromeClient(new WebChromeClient(){
	            @Override
	            public void onConsoleMessage(String message, int lineNumber,String sourceID) {
	                //System.out.println("MyApplication : "+ message + " -- From line "+ lineNumber + " of " + sourceID);
	                super.onConsoleMessage(message, lineNumber, sourceID);
	            }
	      }); 
	}
	

	public void close(View view) {
		Intent intent = new Intent(this, CloudMenu.class);
		this.startActivity(intent);
	}

	public void neverShowAgain(View view) {
		saveSettings(true);
		close(view);
	}

	private void saveSettings(boolean neverShowAgain) {
		SharedPreferences settings = this.getSharedPreferences(this.getClass()
				.getName(), MODE_PRIVATE);
		SharedPreferences.Editor editor = settings.edit();
		editor.putBoolean("neverShowAgain", neverShowAgain);
		editor.commit();
	}
}